<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();   
String url ="jdbc:mysql://localhost/bbs?user=root&password=198311&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);  
ResultSet rs = null;
String userName = request.getParameter("username");
String password = request.getParameter("password");
String mail = request.getParameter("mail");
String sex = request.getParameter("sex");
PreparedStatement stmt1 = conn.prepareStatement("select * from user where name = ?;");
stmt1.setString(1,userName);
rs = stmt1.executeQuery();
if(rs.next()){
	System.out.println("register failed , this name is registered!");
	session.setAttribute("login_msg","register failed , this name is registered!");
	response.sendRedirect("signup.jsp");
	return;
}
PreparedStatement stmt = conn.prepareStatement("insert User values (?,?,?,?,?);");

stmt.setString(1,userName);
stmt.setString(2,password);
stmt.setString(3,mail);
stmt.setString(4,sex);
stmt.setInt(5,5);
stmt.executeUpdate();


System.out.println("your Name is " + userName);
System.out.println("your Mail is " + mail);
System.out.println("your Sex is " + sex);

%>

 
<% 
stmt.close();   
conn.close();   
session.setAttribute("login_msg","Register successfully!");
response.sendRedirect("index.jsp");
%>  
</body>
</html>